package com.marisfrolg.adapter;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Locale;
import java.util.Random;

import com.lidroid.xutils.DbUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.exception.DbException;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.marisfrolg.entity.Model;

import android.content.Context;
import android.graphics.Color;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class RemindAdapter extends BaseAdapter {
	// 定义Context
	private Context mContext;
	// 定义整型数组 即图片源
	private List<Model> models;

	public RemindAdapter(Context c) throws DbException {
		mContext = c;
		DbUtils db = DbUtils.create(mContext,Environment.getExternalStorageDirectory().getPath() + "/storage/","storage.db");
		models=db.findAll(Model.class);
	}

	// 获取图片的个数
	public int getCount() {
		if(models==null){
			return 0;
		}
		return models.size();
	}

	// 获取图片在库中的位置
	public Object getItem(int position) {
		return position;
	}

	// 获取图片ID
	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {//容器控件调用这个方法来插入子控件
//		LayoutInflater inflater=LayoutInflater.from(mContext);
//		View v=inflater.inflate(R.layout.todayremind_item, null);//直接从布局文件转化为view对象
//		//不知道这种情况下,怎么把v加入到xutils里面的ioc中,所以还是原始的取得对象方法
//		RelativeLayout todayreminditem=(RelativeLayout)v.findViewById(R.id.todayreminditem);
//		// 设置布局
//        todayreminditem.setLayoutParams(new GridView.LayoutParams(180, 120));
//        Random random=new Random();
//        int r,b,g;
//    	r=random.nextInt(255);
//        b=random.nextInt(255);
//        g=random.nextInt(255);
//        v.setBackgroundColor( Color.argb(130,r,b,g));//130透明度,255不透明,随机背景颜色
//        TextView time=(TextView)v.findViewById(R.id.itemtime);
//        TextView thing=(TextView)v.findViewById(R.id.itemthing);
//        SimpleDateFormat fmt=new SimpleDateFormat("HH:mm aa",Locale.US);
//        time.setText(fmt.format(reminders.get(position).getTime()));
//        thing.setText(reminders.get(position).getThing());
		return convertView;
	}
}
